#pragma once

#include <QDrag>
#include <QDropEvent>
#include <QListView>
#include <QMimeData>
#include <QMouseEvent>
#include <QStandardItemModel>
#include <QStyledItemDelegate>

#include "widgets.h"

class S_WIDGETS_EXPORT SDragListItemDelegate : public QStyledItemDelegate {
 public:
  SDragListItemDelegate(QObject *p) {}
  virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
                     const QModelIndex &index) const override;
};

class S_WIDGETS_EXPORT SDragListItemModel : public QStandardItemModel {
  Q_OBJECT

 public:
  SDragListItemModel(QObject *parent = nullptr) : QStandardItemModel(parent) {}

  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
                    int column, const QModelIndex &parent) override;
};

class S_WIDGETS_EXPORT SDragListWidget : public QListView {
  Q_OBJECT

 public:
  SDragListWidget(QWidget *parent = nullptr);

  void addItem(const QString &text);

 protected:
  void startDrag(Qt::DropActions supportedActions) override;

  void dropEvent(QDropEvent *event) override;
  void dragEnterEvent(QDragEnterEvent *event) override;
  void dragMoveEvent(QDragMoveEvent *event) override;
};
